local zong__jiangxin = fk.CreateSkill {
  name = "zong__jiangxin",
}

Fk:loadTranslationTable{
  ["zong__jiangxin"] = "匠心",
  [":zong__jiangxin"] = "出牌阶段,你可以改为依次弃置至多两名其他角色区域内的各一张牌。",

  ["#zong__jiangxin-choose"] = "匠心：你可以改为依次弃置一至两名其他角色区域内的各一张牌",
}

zong__jiangxin:addEffect(fk.EventPhaseStart, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player
    and player:hasSkill(zong__jiangxin.name)
    and data.phase == Player.Play
  end,

  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room:getOtherPlayers(player, false), function (p)
      return not p:isAllNude()
    end)
    local to = room:askToChoosePlayers(player, {
      skill_name = zong__jiangxin.name,
      min_num = 1,
      max_num = 1,
      targets = targets,
      prompt = "#zong__jiangxin-choose",
      cancelable = true,
    })
    if #to > 0 then
      room:sortByAction(to)
      event:setCostData(self, {tos = to})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    local card = room:askToChooseCard(player, {
      target = to,
      flag = "hej",
      skill_name = zong__jiangxin.name,
    })
    room:throwCard(card, zong__jiangxin.name, to, player)
    if player.dead then return false end
    local targets = table.filter(room:getOtherPlayers(player, false), function (p)
      return not p:isAllNude()
      and p ~= to
    end)
    if #targets > 0 then
      to = room:askToChoosePlayers(player, {
      targets = targets,
      min_num = 1,
      max_num = 1,
      prompt = "#zong__jiangxin-choose",
      skill_name = zong__jiangxin.name,
      cancelable = true,
      })
      if #to > 0 then
      to = to[1]
      card = room:askToChooseCard(player, {
        target = to,
        flag = "hej",
        skill_name = zong__jiangxin.name,
      })
      room:throwCard(card, zong__jiangxin.name, to, player)
      end
    end
    player:endPlayPhase()
  end,
})

return zong__jiangxin